<template>
  <el-dialog
    :show-close="showClose"
    :draggable="true"
    :model-value="show"
    close-on-click-modal="false"
    :title="title"
    class="cust-dialog"
    :width="width"
    :top="top + 'px'"
    @close="close"
  >
    <div class="dialog-body">
      <slot> </slot>
    </div>
    <template v-if="(buttons && buttons.length > 0) || showCancel">
      <div class="dialog-footer">
        <el-button @click="close" v-if="showCancel" link>取消</el-button>
        <el-button
          v-for="(btn, i) in buttons"
          :key="i"
          :type="btn.type || 'primary'"
          @click="btn.click"
          >{{ btn.text }}</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>
  
  <script setup>
const props = defineProps({
  show: {
    type: Boolean,
    default: false,
  },
  title: {
    type: String,
  },
  showClose: {
    type: Boolean,
    default: true,
  },
  width: {
    type: String,
    default: "30%",
  },
  top: {
    type: String,
    default: "50px",
  },
  buttons: {
    type: Array,
  },
  showCancel: {
    type: Boolean,
    default: true,
  },
  padding: {
    type: Number,
    default: 15,
  },
});
const maxHeight = window.innerHeight - props.top - 100;
const emit = defineEmits();
// 把close方法暴露出去
const close = () => {
  emit("close");
};
</script>
  
  <style lang="scss">
.cust-dialog {
  margin: 30px auto 10px !important;
  .dialog-body {
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
    padding: 15px;
    min-height: 100px;
    // max-height: calc(100vh - 220px);
    overflow: auto;
  }
  .dialog-footer {
    text-align: right;
    padding: 5px 20px;
  }
  .el-dialog__body {
    padding: 0;
  }
}
</style>